package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingProjectController
 * @Author Hua Caoxing
 * @Data 2025-08-28
 */
@Slf4j
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 获取护理项目列表
     *
     * @param pageNUm  页码
     * @param pageSize 每页数量
     * @param name     护理项目名称
     * @param status   护理项目状态
     * @return 护理项目列表
     */
    @GetMapping
    @ApiOperation(value = "获取护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getNursingProjectList(@ApiParam(value = "页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNUm,
                                                                                @ApiParam(value = "每页数量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                @ApiParam(value = "护理项目名称") @RequestParam(value = "name", required = false) String name,
                                                                                @ApiParam(value = "护理项目状态") @RequestParam(value = "status", required = false) Integer status) {

        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getNursingProjectList(pageNUm, pageSize, name, status);
        return success(pageResponse);
    }

    /**
     * 添加护理项目
     *
     * @param nursingProjectVo 护理项目VO对象
     * @return 响应结果
     */
    @PostMapping
    @ApiOperation(value = "添加护理项目")
    @ApiImplicitParam(name = "nursingProjectVo", value = "护理项目VO对象", required = true, dataType = "NursingProjectVo")
    public ResponseResult addNursingProject(@RequestBody NursingProjectVo nursingProjectVo) {
        log.info("添加护理项目");
        nursingProjectService.addNursingProject(nursingProjectVo);
        return success();
    }

    /**
     * 根据ID查询护理项目
     * @param id 护理项目ID
     * @return 护理项目VO对象
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询护理项目")
    @ApiImplicitParam(name = "id", value = "护理项目ID", required = true, dataType = "Long")
    public ResponseResult<NursingProjectVo> findNursingProjectById(@PathVariable Long id) {
        log.info("根据ID查询护理项目");
        NursingProjectVo nursingProjectVo = nursingProjectService.findNursingProjectById(id);
        return success(nursingProjectVo);
    }

    /**
     * 更新护理项目
     *
     * @param nursingProjectVo 护理项目VO对象
     * @return 响应结果
     */
    @PutMapping
    @ApiOperation(value = "更新护理项目")
    @ApiImplicitParam(name = "nursingProjectVo", value = "护理项目VO对象", required = true, dataType = "NursingProjectVo")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectVo nursingProjectVo) {
        log.info("更新护理项目");
        nursingProjectService.updateNursingProject(nursingProjectVo);
        return success();
    }

    /**
     * 删除护理项目
     *
     * @param id 护理项目ID
     * @return 响应结果
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目")
    @ApiImplicitParam(name = "id", value = "护理项目ID", required = true, dataType = "Long")
    public ResponseResult deleteNursingProject(@PathVariable Long id) {
        log.info("删除护理项目");
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    /**
     * 更新护理项目状态
     *
     * @param id     护理项目ID
     * @param status 护理项目状态
     * @return 响应结果
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "更新护理项目状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "护理项目ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "status", value = "护理项目状态", required = true, dataType = "Integer")
    })
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        log.info("更新护理项目状态");
        nursingProjectService.updateStatus(id, status);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation(value = "获取所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAll(){
        log.info("获取所有护理项目");
        List<NursingProjectVo> list = nursingProjectService.getAll();
        return success(list);
    }
}
